<%@ page import="jakarta.servlet.http.Cookie" %><%--
  Created by IntelliJ IDEA.
  User: LH
  Date: 2022/9/9
  Time: 16:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<%
    String freeLogin = request.getParameter("freeLogin");
    System.out.println(freeLogin);
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    application.setAttribute("username",username);
    application.setAttribute("password",password);
    if (username!=null&password!=null&username.equals("雷华")&password.equals("2040706301")){
       if (freeLogin.equals("on")){
           Cookie cookie1 = new Cookie("name", username);
           Cookie cookie2 = new Cookie("password", password);
           cookie1.setMaxAge(7*60*60);
           cookie2.setMaxAge(7*60*60);
           response.addCookie(cookie1);
           response.addCookie(cookie2);
       }
        //request.getRequestDispatcher("index.jsp").forward(request,response);
            response.sendRedirect("index.jsp");
    }
    else{
%>
<script>
    alert("用户名或密码错误,两秒后自动跳转登录页面");
</script>
<%
        //Thread.sleep(2000);
        request.getRequestDispatcher("login.jsp").forward(request,response);
    }
%>
</body>
</html>
